
******************************************************
* 				Replication do-file                  *
*         Review of Economics and Statistics         *
*                                                    *
*               Choosing Your Pond                   *
*       Location Choices and Relative Income         *
*                                                    *
*		Nicolas Bottan & Ricardo Perez-Truglia       *
*                                                    *
*                   September 2020                   *
*                                                    *
******************************************************
/*

                    Notes
					
This do-file replicates Appendix Tables A from the paper. 

The analysis makes use of survey data on medical students 
participating in the NRMP, and as such is highly sensitive
and cannot be posted.

Please contact the authors if you are interested in having
them conduct any additional analysis.

*** Install Stata commands
cap: ssc install renames
cap: ssc install ivreg2
cap: ssc install ranktest 
cap: ssc install esttab
cap: ssc install outreg2
cap: ssc install parmest
cap: ssc install qqvalue
cap: ssc install quantiles

*/



*** Set WD

cd ""		// Set path for main folder here



*** Appendix Table A1: Descriptive Statistics and Randomization Balance

use "Main Experiment/mainexperiment_confidential.dta", clear

global controls "rel_res rel_qol lnpop reldens relblack reldemocrat relurban"

gen treatments="RPP; ACS" if trat=="11"
replace treatments="RPP; CPS" if trat=="12"
replace treatments="COLI; ACS" if trat=="21"
replace treatments="COLI; CPS" if trat=="22"

gen nrtr=1 if trat=="11"
replace nrtr=2 if trat=="12"
replace nrtr=3 if trat=="21"
replace nrtr=4 if trat=="22"

replace pre_relpx=pre_relpx*100
replace pre_relinc=pre_relinc*100

postfile desc str20 variable str12 all str12 RppAcs str12 RppCps str12 ColiAcs str12 ColiCps str12 pvalue using results/AppendixTableA1.dta, replace

foreach var in male age nkids single dualmatch usnewsrank pre_relpx pre_relinc  {

	sum `var'
	local m0=string(r(mean), "%9.3f")
	local s0=string(r(sd)/sqrt(r(N)), "%9.3f")

	forvalues i=1/4 {
		sum `var' if nrtr==`i'
		local m`i'=string(r(mean), "%9.3f")
		local s`i'=string(r(sd)/sqrt(r(N)), "%9.3f")
	}
	
	reg `var' i.nrtr, r
	local p=string(Ftail(e(df_m),e(df_r),e(F)), "%9.3f")
	
	post desc ("`var'") ("`m0'") ("`m1'") ("`m2'") ("`m3'") ("`m4'") ("`p'")
	post desc ("") ("(`s0')") ("(`s1')") ("(`s2')") ("(`s3')") ("(`s4')") ("")
	
	post desc ("") ("") ("") ("") ("") ("") ("")
	}

cou
local m0=string(r(N), "%9.0fc")
forvalues i=1/4 {
	cou if nrtr==`i'
	local m`i'=r(N)
	}

post desc ("Observations") ("`m0'") ("`m1'") ("`m2'") ("`m3'") ("`m4'") ("")

replace pre_relpx=pre_relpx/100
replace pre_relinc=pre_relinc/100

postclose desc









*** Appendix Table A2: Comparison between Participating and Non-Participating Medical Schools

use "Main Experiment/usanews_descriptives.dta", clear // This data is propriatery and cannot be freely distributed. Data access can be purchased through USA News

* Fix assignments
replace contacted="Y" if insample==1
replace contacted="NR" if id==12

* Drop universities that were not contacted (ie. not in directory)
drop if contacted=="N"

rename Totalmedicalsch enrollment
gen miss_enrollment=enrollment==.

rename MedianMCAT mcat
gen miss_mcat=mcat==.

rename Medianunder gpa
gen miss_gpa=gpa==.

rename Acceptance accept
gen miss_accept=accept==.

replace rank=. if rank<0
gen miss_rank=rank==.

gen miss_tuitionos=tuitionos==.

rename Fulltimefaculty facultyps
gen miss_facultyps=facultyps==.

rename Peerassess peerassess
gen miss_peerassess=peerassess==.

postfile desc str20 variable str12 all str12 nonpart str12 part str12 pval using AppendixTableA2.dta, replace

foreach var in enrollment mcat gpa accept rank tuitionos facultyps peerassess {

	sum `var'
	local m0=string(r(mean), "%9.3f")
	local s0=string(r(sd)/sqrt(r(N)), "%9.3f")
	
	sum `var' if insample==0
	local m1=string(r(mean), "%9.3f")
	local s1=string(r(sd)/sqrt(r(N)), "%9.3f")

	sum `var' if insample==1
	local m2=string(r(mean), "%9.3f")
	local s2=string(r(sd)/sqrt(r(N)), "%9.3f")

	reg `var' insample, r
	local p= string(ttail(e(df_r), abs(_b[insample]/_se[insample]))*2, "%9.3f")
	
	post desc ("`var'") ("`m0'") ("`m1'") ("`m2'") ("`p'")
	post desc ("") ("(`s0')") ("(`s1')") ("(`s2')") ("")
	
	sum miss_`var'
	local m0=string(r(mean), "%9.3f")
	local s0=string(r(sd)/sqrt(r(N)), "%9.3f")
	
	sum miss_`var' if insample==0
	local m1=string(r(mean), "%9.3f")
	local s1=string(r(sd)/sqrt(r(N)), "%9.3f")

	sum miss_`var' if insample==1
	local m2=string(r(mean), "%9.3f")
	local s2=string(r(sd)/sqrt(r(N)), "%9.3f")

	reg miss_`var' insample, r
	local p= string(ttail(e(df_r), abs(_b[insample]/_se[insample]))*2, "%9.3f")

	post desc ("`var'") ("`m0'") ("`m1'") ("`m2'") ("`p'")
	post desc ("") ("(`s0')") ("(`s1')") ("(`s2')") ("")
	post desc ("") ("") ("") ("") ("")
	}

cou
local m0=r(N)
cou if insample==0
local m1=r(N)
cou if insample==1
local m2=r(N)

post desc ("Observations") ("`m0'") ("`m1'") ("`m2'") ("")

postclose desc










*** Appendix Table A4: Comparison of Characteristics between Respondents to Baseline and Follow-Up Surveys

use "Main Experiment/mainexperiment_confidential.dta", clear

replace finishedfollowup=(finalra!=. & gap_follow!=.)

gen treat1=sourcecol=="colhat"
gen treat2=sourceinc=="acs"

postfile desc str20 variable str12 all str12 nonpart str12 part str12 pval using results/AppendixTableA4.dta, replace

foreach var in male age nkids single dualmatch treat1 treat2 diffwage rel_res attnchk pre_relinc pre_relpx post_relinc post_relpx {

	sum `var'
	local m0=r(mean)
	local s0=r(sd)/sqrt(r(N))
	
	sum `var' if finishedfollowup==0
	local m1=r(mean)
	local s1=r(sd)/sqrt(r(N))

	sum `var' if finishedfollowup==1
	local m2=r(mean)
	local s2=r(sd)/sqrt(r(N))

	reg `var' finishedfollowup, r
	local p= ttail(e(df_r), abs(_b[finishedfollowup]/_se[finishedfollowup]))*2
	
	post desc ("`var'") ("`m0'") ("`m1'") ("`m2'") ("`p'")
	post desc ("") ("`s0'") ("`s1'") ("`s2'") ("")
	
	post desc ("") ("") ("") ("") ("")
	}

cou
local m0=r(N)
cou if finishedfollowup==0
local m1=r(N)
cou if finishedfollowup==1
local m2=r(N)

post desc ("Observations") ("`m0'") ("`m1'") ("`m2'") ("")

postclose desc










*** Appendix Table A5: Comparison of Characteristics between Experimental Subjects and the General U.S. Population

** Experimental subjects
use "Main Experiment/mainexperiment_confidential.dta", clear

cap: gen married=marital==2
egen wage=rowmean(wage1 wage2)
gen usborn=growupusa=="Yes" if growupusa!=""

sum age male married wage usborn

** General US Population
use acs2015p, clear		// 2015 ACS PUMS data accessible via the ACS website.

** Sample restrictions
* Keep employed individuals
keep if inlist(esr,1,2)

* Drop missing/no income
drop if wagp==. | wagp==0

* Drop if self-employed
drop if inlist(cow,6,7,8,9)

* Keep Adults
drop if age<21 | age>65

*** Prepare variables
gen male=sex==1

gen wage=wagp*1.01754
gen earn=pernp*1.01754

gen married=mar==1

* age
gen usborn=cit==1

gen mtcoll=inlist(schl,22,23,24)

sum age male married wage usborn mtcoll [w=pwgtp]










*** Appendix Table A6: Location Preferences: Probit Marginal Effects

use "Main Experiment/mainexperiment_confidential.dta", clear

eststo clear

* ALL
cap: drop RELINC0 RELPX0
gen RELINC0=post_relinc
gen RELPX0=post_relpx

probit baseline_finalrank RELINC0 RELPX0 lndiffwage $controls, robust
eststo row1

probit baseline_finalrank RELINC0 RELPX0 lndiffwage $controls, robust
eststo row2: mfx

probit baseline_finalrank RELINC0 RELPX0 lndiffwage $controls if lr_relpx!=., robust
eststo row3

probit baseline_finalrank RELINC0 RELPX0 lndiffwage $controls if lr_relpx!=., robust
eststo row4: mfx

esttab, margin keep(RELINC0 RELPX0) order(RELINC0 RELPX0) se

mat list r(coefs)
mat define A0=r(coefs)
matselrc A0 A, c(1 2 3 5 6 7 9 10 11 13 14 15)
matrix drop A0
eststo drop row*
local rnames : rownames A
local models : coleq A
local models : list uniq models

local i=0
foreach name in RELINC0 RELPX0 {
 local ++i
 local j 0
 cap: matrix drop b
 cap: matrix drop se
 cap: matrix drop p
 foreach model of local models {
 local ++j
 matrix tmp = A[`i', 3*`j'-2]
 if tmp[1,1]<. {
 matrix colnames tmp = `model'
 matrix b = nullmat(b), tmp
 matrix tmp[1,1] = A[`i', 3*`j'-1]
 matrix se = nullmat(se), tmp
 matrix tmp[1,1] = A[`i', 3*`j']
 matrix p = nullmat(p), tmp
 }
 }
 ereturn post b
 quietly estadd matrix se
 quietly estadd matrix p
 eststo `name'
 qui cou if finalrank!=. & lr_relpx!=.
 qui estadd scalar obs=r(N)

 }

esttab, se mtitle noobs star(* .1 ** .05 *** .01) stats(obs)

matrix drop A


* Non-Single
cap: drop RELINC1 RELPX1
gen RELINC1=post_relinc
gen RELPX1 = post_relpx

probit baseline_finalrank RELINC1 RELPX1 lndiffwage $controls if single==0, robust
eststo row1

probit baseline_finalrank RELINC1 RELPX1 lndiffwage $controls if single==0, robust
eststo row2: mfx

probit baseline_finalrank RELINC1 RELPX1 lndiffwage $controls if lr_relpx!=. & single==0, robust
eststo row3

probit baseline_finalrank RELINC1 RELPX1 lndiffwage $controls if lr_relpx!=. & single==0, robust
eststo row4: mfx

esttab, margin keep(RELINC1 RELPX1) order(RELINC1 RELPX1) se

mat list r(coefs)
mat define A0=r(coefs)
matselrc A0 A, c(9 10 11 13 14 15 17 18 19 21 22 23)
matrix drop A0
eststo drop row*
local rnames : rownames A
local models : coleq A
local models : list uniq models

local i=0
foreach name in RELINC1 RELPX1 {
 local ++i
 local j 0
 cap: matrix drop b
 cap: matrix drop se
 cap: matrix drop p
 foreach model of local models {
 local ++j
 matrix tmp = A[`i', 3*`j'-2]
 if tmp[1,1]<. {
 matrix colnames tmp = `model'
 matrix b = nullmat(b), tmp
 matrix tmp[1,1] = A[`i', 3*`j'-1]
 matrix se = nullmat(se), tmp
 matrix tmp[1,1] = A[`i', 3*`j']
 matrix p = nullmat(p), tmp
 }
 }
 ereturn post b
 quietly estadd matrix se
 quietly estadd matrix p
 eststo `name'
 qui cou if single==0 & finalrank!=. & lr_relpx!=.
 qui estadd scalar obs=r(N)
 
 }

esttab, se mtitle noobs star(* .1 ** .05 *** .01)

matrix drop A


* Single
cap: drop RELINC2 RELPX2
gen RELINC2=post_relinc
gen RELPX2= post_relpx


probit baseline_finalrank RELINC2 RELPX2 lndiffwage $controls if single==1, robust
eststo row1

probit baseline_finalrank RELINC2 RELPX2 lndiffwage $controls if single==1, robust
eststo row2: mfx

probit baseline_finalrank RELINC2 RELPX2 lndiffwage $controls if lr_relpx!=. & single==1, robust
eststo row3

probit baseline_finalrank RELINC2 RELPX2 lndiffwage $controls if lr_relpx!=. & single==1, robust
eststo row4: mfx


esttab, margin keep(RELINC2 RELPX2) order(RELINC2 RELPX2) se

mat list r(coefs)
mat define A0=r(coefs)
matselrc A0 A, c(17 18 19 21 22 23 25 26 27 29 30 31)
matrix drop A0
eststo drop row*
local rnames : rownames A
local models : coleq A
local models : list uniq models

local i=0
foreach name in RELINC2 RELPX2 {
 local ++i
 local j 0
 cap: matrix drop b
 cap: matrix drop se
 cap: matrix drop p
 foreach model of local models {
 local ++j
 matrix tmp = A[`i', 3*`j'-2]
 if tmp[1,1]<. {
 matrix colnames tmp = `model'
 matrix b = nullmat(b), tmp
 matrix tmp[1,1] = A[`i', 3*`j'-1]
 matrix se = nullmat(se), tmp
 matrix tmp[1,1] = A[`i', 3*`j']
 matrix p = nullmat(p), tmp
 }
 }
 ereturn post b
 quietly estadd matrix se
 quietly estadd matrix p
 eststo `name'
 qui cou if single==1 & finalrank!=. & lr_relpx!=.
 qui estadd scalar obs=r(N)
 }

esttab, se mtitle noobs star(* .1 ** .05 *** .01)

matrix drop A


local t0 " & \multicolumn{3}{c}{Panel A: \$ \beta^{ER} \$ } & \multicolumn{3}{c}{Panel B: \$ \beta^{COL} \$} \\ \cmidrule(lr){2-4} \cmidrule(lr){5-7} "
local t1 " & Non-Single & Single  & All & Non-Single & Single & All \\"
local t2 " &(1)&(2)&(3)&(4)&(5)&(6) \\ \midrule"

esttab  RELINC1 RELINC2 RELINC0  RELPX1 RELPX2 RELPX0 using "results/AppendixTableA6.tex", se nonotes noconstant label replace booktabs gap compress  b(%9.3f) se(%9.3f) star(* 0.1 ** 0.05 *** 0.01) nonumbers mlabels(none) eqlabels(none) coeflabels(row1 "Raw Probit" row2 "Marginal Effect" row3 "Raw Probit" row4 "Marginal Effect") posthead("`t0'" "`t1'" "`t2'")










*** Appendix Table A7: Location Preferences: Sensitivity to Sample Definition

use "Main Experiment/mainexperiment_confidential.dta", clear

eststo clear

global controls "rel_res rel_qol lnpop reldens relblack reldemocrat relurban"

* ALL
cap: drop RELINC0 RELPX0
gen RELINC0=post_relinc
gen RELPX0=post_relpx

probit baseline_finalrank RELINC0 RELPX0 lndiffwage $controls, robust
eststo row1

probit baseline_finalrank RELINC0 RELPX0 lndiffwage $controls if attn==1, robust
eststo row2

probit baseline_finalrank RELINC0 RELPX0 lndiffwage $controls if dual==0, robust
eststo row3

esttab, keep(RELINC0 RELPX0) order(RELINC0 RELPX0) se

mat list r(coefs)
mat define A=r(coefs)
eststo drop row*
local rnames : rownames A
local models : coleq A
local models : list uniq models

local i=0
foreach name in RELINC0 RELPX0 {
 local ++i
 local j 0
 cap: matrix drop b
 cap: matrix drop se
 cap: matrix drop p
 foreach model of local models {
 local ++j
 matrix tmp = A[`i', 3*`j'-2]
 if tmp[1,1]<. {
 matrix colnames tmp = `model'
 matrix b = nullmat(b), tmp
 matrix tmp[1,1] = A[`i', 3*`j'-1]
 matrix se = nullmat(se), tmp
 matrix tmp[1,1] = A[`i', 3*`j']
 matrix p = nullmat(p), tmp
 }
 }
 ereturn post b
 quietly estadd matrix se
 quietly estadd matrix p
 eststo `name'
 qui cou if finalrank!=. & lr_relpx!=.
 qui estadd scalar obs=r(N)

 }

esttab, se mtitle noobs star(* .1 ** .05 *** .01) stats(obs)

matrix drop A


* Non-Single
cap: drop RELINC1 RELPX1
gen RELINC1=post_relinc
gen RELPX1 = post_relpx

probit baseline_finalrank RELINC1 RELPX1 lndiffwage $controls if single==0, robust
eststo row1

probit baseline_finalrank RELINC1 RELPX1 lndiffwage $controls if attn==1 & single==0, robust
eststo row2

probit baseline_finalrank RELINC1 RELPX1 lndiffwage $controls if dual==0 & single==0, robust
eststo row3

esttab, keep(RELINC1 RELPX1) order(RELINC1 RELPX1) se

mat list r(coefs)
mat define A=r(coefs)
eststo drop row*
local rnames : rownames A
local models : coleq A
local models : list uniq models

local i=0
foreach name in RELINC1 RELPX1 {

 local ++i
 local j 0
 cap: matrix drop b
 cap: matrix drop se
 cap: matrix drop p
 foreach model of local models {
 local ++j
 matrix tmp = A[`i', 3*`j'-2]
 if tmp[1,1]<. {
 matrix colnames tmp = `model'
 matrix b = nullmat(b), tmp
 matrix tmp[1,1] = A[`i', 3*`j'-1]
 matrix se = nullmat(se), tmp
 matrix tmp[1,1] = A[`i', 3*`j']
 matrix p = nullmat(p), tmp
 }
 }
 ereturn post b
 quietly estadd matrix se
 quietly estadd matrix p
 eststo `name'
 qui cou if single==0 & finalrank!=. & lr_relpx!=.
 qui estadd scalar obs=r(N)
 
 }

esttab, se mtitle noobs star(* .1 ** .05 *** .01)

matrix drop A


* Single
cap: drop RELINC2 RELPX2
gen RELINC2=post_relinc
gen RELPX2= post_relpx

probit baseline_finalrank RELINC2 RELPX2 lndiffwage $controls if single==1, robust
eststo row1

probit baseline_finalrank RELINC2 RELPX2 lndiffwage $controls if attn==1 & single==1, robust
eststo row2

probit baseline_finalrank RELINC2 RELPX2 lndiffwage $controls if dual==0 & single==1, robust
eststo row3

esttab, keep(RELINC2 RELPX2) order(RELINC2 RELPX2) se

mat list r(coefs)
mat define A=r(coefs)
eststo drop row*
local rnames : rownames A
local models : coleq A
local models : list uniq models

local i=0
foreach name in RELINC2 RELPX2 {
 local ++i
 local j 0
 cap: matrix drop b
 cap: matrix drop se
 cap: matrix drop p
 foreach model of local models {
 local ++j
 matrix tmp = A[`i', 3*`j'-2]
 if tmp[1,1]<. {
 matrix colnames tmp = `model'
 matrix b = nullmat(b), tmp
 matrix tmp[1,1] = A[`i', 3*`j'-1]
 matrix se = nullmat(se), tmp
 matrix tmp[1,1] = A[`i', 3*`j']
 matrix p = nullmat(p), tmp
 }
 }
 ereturn post b
 quietly estadd matrix se
 quietly estadd matrix p
 eststo `name'
 qui cou if single==1 & finalrank!=. & lr_relpx!=.
 qui estadd scalar obs=r(N)
 }

esttab, se mtitle noobs star(* .1 ** .05 *** .01)

matrix drop A

local t0 " & \multicolumn{3}{c}{Panel A: \$ \beta^{ER} \$ } & \multicolumn{3}{c}{Panel B: \$ \beta^{COL} \$} \\ \cmidrule(lr){2-4} \cmidrule(lr){5-7} "
local t1 " & Non-Single & Single  & All & Non-Single & Single & All \\"
local t2 " &(1)&(2)&(3)&(4)&(5)&(6) \\ \midrule"

esttab  RELINC1 RELINC2 RELINC0 RELPX1 RELPX2 RELPX0 using "results/AppendixTableA7.tex", se nonotes noconstant label replace booktabs gap compress  b(%9.3f) se(%9.3f) star(* 0.1 ** 0.05 *** 0.01) nonumbers mlabels(none) eqlabels(none) coeflabels(row1 "Baseline Sample" row2 "Pass Attention Check" row3 "Drop Dual Matches") posthead("`t0'" "`t1'" "`t2'")










*** Appendix Table A8: Location Preferences: Sensitivity to Sample Definition

use "Main Experiment/mainexperiment_confidential.dta", clear

eststo clear

global controls "rel_res rel_qol lnpop reldens relblack reldemocrat relurban"

probit baseline_finalrank post_relinc post_relpx lndiffwage $controls, robust
estimates store ols1

* Non-Single vs Single
probit baseline_finalrank post_relinc post_relpx lndiffwage $controls if single==0, robust
estimates store ols2

probit baseline_finalrank post_relinc post_relpx lndiffwage $controls if single==1, robust
estimates store ols3


probit baseline_finalrank post_relinc post_relpx lndiffwage $controls if potential==0, robust
estimates store ols4

* Non-Single vs Single
probit baseline_finalrank post_relinc post_relpx lndiffwage $controls if single==0 & potential==0, robust
estimates store ols5

probit baseline_finalrank post_relinc post_relpx lndiffwage $controls if single==1 & potential==0, robust
estimates store ols6

local t0 "  & \multicolumn{3}{c}{All} & \multicolumn{3}{c}{Drop Repeat Metro}  \\ \cmidrule(lr){2-4} \cmidrule(lr){5-7}"
local t1 "  & & \multicolumn{2}{c}{By Relationship Status} & & \multicolumn{2}{c}{By Relationship Status}  \\ \cmidrule(lr){3-4}"
local t2 " & All & Non-Single & Single & All & Non-Single & Single "
local t3 " &(1)&(2)&(3)&(4)&(5)&(6) \\ \midrule"

esttab ols1 ols2 ols3 ols4 ols5 ols6 using "results/AppendixTableA8.tex", se nonotes noconstant label replace booktabs gap compress keep(post_relinc post_relpx) order(post_relinc post_relpx)  b(%9.3f) se(%9.3f) star(* 0.1 ** 0.05 *** 0.01)  stats(p1 p2 r2_p N, fmt(%9.3f %9.3f %9.3f %9.0fc) labels("Relative" "Absolute" "Pseudo \$R^2\$" "Observations")) nonumbers posthead("`t0'" "`t1'" "`t2'" "`t3'") mlabels(none) eqlabels(none) coeflabels(post_relinc "$\beta^{ER}$" post_relpx "$\beta^{COL}$")










*** Appendix Table A9: Location Preferences: Sensitivity to Largest and Smallest Metro Areas

use "Main Experiment/mainexperiment_confidential.dta", clear

eststo clear

global hospquality "rel_mort rel_read rel_score mort_10pct1 read_10pct1 score_10pct1 mort_10pct2 read_10pct2 score_10pct2"

global controls "rel_res rel_qol lnpop reldens relblack reldemocrat relurban"

global objprogrchar "rel_res proguniA proguniB"
global subjprogrchar "po_purpose po_prestige po_prospects"

gen maxcity=max(pop1,pop2)
gen mincity=min(pop1,pop2)

eststo clear

forvalues k=1/3 {

if `k'==1 {
	global ifcond "if maxcity"
	}
else if `k'==2 {
	global ifcond "if single==0 & maxcity"
	}
else {
	global ifcond "if single==1 & maxcity"
	}

probit baseline_finalrank post_relinc post_relpx lndiffwage $controls $ifcond >0, robust
eststo row1

probit baseline_finalrank post_relinc post_relpx lndiffwage $controls $ifcond <9500000, robust
eststo row2

probit baseline_finalrank post_relinc post_relpx lndiffwage $controls $ifcond >0 & mincity>160000, robust
eststo row3

cap: eststo drop post_relinc post_relpx r2_p
esttab row*, keep(post_relinc post_relpx) order(post_relinc post_relpx) se stat(r2_p)

mat list r(coefs)
mat define A=r(coefs)
mat list r(stats)
mat define R=r(stats)

eststo drop row*
local rnames : rownames A
local models : coleq A
local models : list uniq models

local i=0
foreach name in post_relinc post_relpx {
 local ++i
 local j 0
 cap: matrix drop b
 cap: matrix drop se
 cap: matrix drop p
 foreach model of local models {
 local ++j
 matrix tmp = A[`i', 3*`j'-2]
 if tmp[1,1]<. {
 matrix colnames tmp = `model'
 matrix b = nullmat(b), tmp
 matrix tmp[1,1] = A[`i', 3*`j'-1]
 matrix se = nullmat(se), tmp
 matrix tmp[1,1] = A[`i', 3*`j']
 matrix p = nullmat(p), tmp
 }
 }
 ereturn post b
 quietly estadd matrix se
 quietly estadd matrix p
 eststo `name'`k'

 }

cap: matrix drop b
cap: matrix drop se
cap: matrix drop p

ereturn post R
eststo PsR`k'

esttab , se mtitle noobs star(* .1 ** .05 *** .01)

cap: matrix drop A
cap: matrix drop R

}

local t1 "& \multicolumn{3}{c}{Panel A: \$ \beta^{ER} \$} & \multicolumn{3}{c}{Panel B: \$ \beta^{COL} \$} & \multicolumn{3}{c}{Pseudo \$ R^2 \$} \\ \cmidrule(lr){2-4}\cmidrule(lr){5-7}\cmidrule(lr){8-10}"
local t2 " & Non-Single & Single & All & Non-Single & Single & All & Non-Single & Single & All  \\"
local t3 " &(1)&(2)&(3)&(4)&(5)&(6)&(7)&(8)&(9)\\ \midrule"

esttab post_relinc2 post_relinc3 post_relinc1 post_relpx2 post_relpx3 post_relpx1  PsR2 PsR3 PsR1 using "results/AppendixTableA9.tex", se nonotes noconstant label replace booktabs gap compress stats() b(%9.3f) se(%9.3f) star(* 0.1 ** 0.05 *** 0.01) nonumbers mlabels(none) eqlabels(none) coeflabels(row1 "Baseline" row2 "3 Largest Metro Areas" row3 "Small Metro Areas") posthead("`t1'" "`t2'" "`t3'")










*** Appendix Table A10: Robustness Check: Additional Controls on Hospital and Residency Programs
use "Main Experiment/mainexperiment_confidential.dta", clear

eststo clear

global resqual "rel_pqual prog_top1 prog_top2"
global hospquality "rel_mort rel_read rel_score mort_10pct1 read_10pct1 score_10pct1 mort_10pct2 read_10pct2 score_10pct2"

global controls "rel_res rel_qol lnpop reldens relblack reldemocrat relurban"

global objprogrchar "rel_res proguniA proguniB"
global subjprogrchar "po_purpose po_prestige po_prospects"

eststo clear

forvalues k=1/3 {

if `k'==1 {
	global ifcond ""
	}
else if `k'==2 {
	global ifcond "if single==0"
	}
else {
	global ifcond "if single==1"
	}

probit baseline_finalrank post_relinc post_relpx lndiffwage $controls $ifcond, robust
eststo row1

probit baseline_finalrank post_relinc post_relpx lndiffwage $controls rel_prog $ifcond, robust
eststo row2

probit baseline_finalrank post_relinc post_relpx lndiffwage $controls rel_prog $resqual $ifcond, robust
eststo row3

probit baseline_finalrank post_relinc post_relpx lndiffwage $controls rel_prog $resqual $objprogrchar $subjprogrchar $ifcond, robust
eststo row4

probit baseline_finalrank post_relinc post_relpx lndiffwage $controls rel_hosp $ifcond, robust
eststo row5

probit baseline_finalrank post_relinc post_relpx lndiffwage $controls rel_hosp $hospquality $ifcond, robust
eststo row6

probit baseline_finalrank post_relinc post_relpx lndiffwage $controls rel_hosp $hospquality $objprogrchar $subjprogrchar $ifcond, robust
eststo row7

probit baseline_finalrank post_relinc post_relpx lndiffwage $controls rel_hosp rel_prog $resqual $hospquality $objprogrchar $subjprogrchar $ifcond, robust
eststo row8

cap: eststo drop post_relinc post_relpx r2_p
esttab row*, keep(post_relinc post_relpx) order(post_relinc post_relpx) se stat(r2_p)

mat list r(coefs)
mat define A=r(coefs)
mat list r(stats)
mat define R=r(stats)

eststo drop row*
local rnames : rownames A
local models : coleq A
local models : list uniq models

local i=0
foreach name in post_relinc post_relpx {
 local ++i
 local j 0
 cap: matrix drop b
 cap: matrix drop se
 cap: matrix drop p
 foreach model of local models {
 local ++j
 matrix tmp = A[`i', 3*`j'-2]
 if tmp[1,1]<. {
 matrix colnames tmp = `model'
 matrix b = nullmat(b), tmp
 matrix tmp[1,1] = A[`i', 3*`j'-1]
 matrix se = nullmat(se), tmp
 matrix tmp[1,1] = A[`i', 3*`j']
 matrix p = nullmat(p), tmp
 }
 }
 ereturn post b
 quietly estadd matrix se
 quietly estadd matrix p
 eststo `name'`k'

 }

cap: matrix drop b
cap: matrix drop se
cap: matrix drop p

ereturn post R
eststo PsR`k'

esttab , se mtitle noobs star(* .1 ** .05 *** .01)

cap: matrix drop A
cap: matrix drop R

}

local t1 "& \multicolumn{3}{c}{Panel A: \$ \beta^{ER} \$} & \multicolumn{3}{c}{Panel B: \$ \beta^{COL} \$} & \multicolumn{3}{c}{Pseudo \$ R^2 \$} \\ \cmidrule(lr){2-4}\cmidrule(lr){5-7}\cmidrule(lr){8-10}"
local t2 " & Non-Single & Single & All & Non-Single & Single & All & Non-Single & Single & All  \\"
local t3 " &(1)&(2)&(3)&(4)&(5)&(6)&(7)&(8)&(9)\\ \midrule"

esttab post_relinc2 post_relinc3 post_relinc1 post_relpx2 post_relpx3 post_relpx1  PsR2 PsR3 PsR1 using "results/AppendixTableA10.tex", se nonotes noconstant label replace booktabs gap compress stats() b(%9.3f) se(%9.3f) star(* 0.1 ** 0.05 *** 0.01) nonumbers mlabels(none) eqlabels(none) coeflabels(row1 "Baseline" row2 "Metro Nr Programs" row3 "Metro Program Quality" row4 "Chosen Program Quality" row5 "Metro Nr Hospitals" row6 "Metro Hosiptal Quality" row7 "Chosen Program Quality" row8 "All") posthead("`t1'" "`t2'" "`t3'")










*** Appendix Table A11: Location Preferences: Subjective Program Characteristics
use "Main Experiment/mainexperiment_confidential.dta", clear

global controls "rel_res rel_qol lnpop reldens relblack reldemocrat relurban"

eststo clear

probit baseline_finalrank post_relpx post_relinc lndiffwage $controls  if lr_relpx!=., robust
local r2= string(e(r2_p), "%9.3f")
eststo bols1
estadd local psr2 = `r2'

probit baseline_finalrank post_relpx post_relinc lndiffwage $controls po_pres if lr_relpx!=., robust
local r2= string(e(r2_p), "%9.3f")
eststo bols2
estadd local psr2 = `r2'

probit baseline_finalrank post_relpx post_relinc lndiffwage $controls po_prospects if lr_relpx!=., robust
local r2= string(e(r2_p), "%9.3f")
eststo bols3
estadd local psr2 = `r2'

probit baseline_finalrank post_relpx post_relinc lndiffwage $controls po_purpose if lr_relpx!=., robust
local r2= string(e(r2_p), "%9.3f")
eststo bols4
estadd local psr2 = `r2'

local t3 "&(1)&(2)&(3)&(4)  \\ \midrule"

esttab bols1 bols4 bols3 bols2 using "results/AppendixTableA11.tex", se nonotes noconstant label replace booktabs gap compress keep(post_relpx post_relinc  po_purpose po_prospects po_prestige) order(post_relinc post_relpx  po_purpose po_prospects po_prestige) b(%9.3f) se(%9.3f) star(* 0.1 ** 0.05 *** 0.01)  stats(psr2 N, fmt(%9.3f %9.0fc) labels("Pseudo \$R^2$" "Observations")) nonumbers posthead("`t3'") mlabels(none) eqlabels(none) refcat(ratio_rel_vs_abs "Trade-offs:", nolabel) coeflabels(post_relinc "\$ S\beta^{ER} \$" post_relpx "\$ S\beta^{COL} \$" po_prestige "\$ \beta^{prestige} \$"  po_prospects "\$ \beta^{prospects} \$"  po_purpose "\$ \beta^{purpose} \$")










*** Appendix Table A12: Location Preferences: Additional Results on Heterogeneity with Respect to Marital Status
use "Main Experiment/mainexperiment_confidential.dta", clear

global controls "rel_res rel_qol lnpop reldens relblack reldemocrat relurban"

eststo clear

probit baseline_finalrank post_relpx post_relinc lndiffwage $controls if single==0 & male==0, robust
estimates store ols1

probit baseline_finalrank post_relpx post_relinc lndiffwage $controls if single==0 & male==1, robust
estimates store ols2

local int male
gen int_px=`int'*post_relpx 
gen int_inc=`int'*post_relinc 
gen interacted=`int'

global intcontrols ""
foreach v in $controls {
	global intcontrols "${intcontrols} c.`v'#c.`int'"
	}

probit baseline_finalrank post_relpx post_relinc int_px int_inc interacted c.lndiffwage#c.interacted lndiffwage $controls $intcontrols if single==0, robust
estadd local p2=string(normal(-abs(_b[int_px]/_se[int_px]))*2, "%9.3f")
estadd local p1=string(normal(-abs(_b[int_inc]/_se[int_inc]))*2, "%9.3f")
drop int_px int_inc interacted

probit baseline_finalrank post_relpx post_relinc lndiffwage $controls if single==1 & male==0, robust
estimates store ols3

probit baseline_finalrank post_relpx post_relinc lndiffwage $controls if single==1 & male==1, robust
estimates store ols4

local int male
gen int_px=`int'*post_relpx 
gen int_inc=`int'*post_relinc 
gen interacted=`int'

global intcontrols ""
foreach v in $controls {
	global intcontrols "${intcontrols} c.`v'#c.`int'"
	}

probit baseline_finalrank post_relpx post_relinc int_px int_inc interacted c.lndiffwage#c.interacted lndiffwage $controls $intcontrols if single==1, robust
estadd local p2=string(normal(-abs(_b[int_px]/_se[int_px]))*2, "%9.3f")
estadd local p1=string(normal(-abs(_b[int_inc]/_se[int_inc]))*2, "%9.3f")
drop int_px int_inc interacted

cap: gen married=marital==2

probit baseline_finalrank post_relpx post_relinc lndiffwage $controls if single==0 & married==1 , robust
estimates store ols5

probit baseline_finalrank post_relpx post_relinc lndiffwage $controls if single==0 & married==0, robust
estimates store ols6

local int married
gen int_px=`int'*post_relpx 
gen int_inc=`int'*post_relinc 
gen interacted=`int'

global intcontrols ""
foreach v in $controls {
	global intcontrols "${intcontrols} c.`v'#c.`int'"
	}

probit baseline_finalrank post_relpx post_relinc int_px int_inc interacted c.lndiffwage#c.interacted lndiffwage $controls $intcontrols if single==0, robust
estadd local p2=string(normal(-abs(_b[int_px]/_se[int_px]))*2, "%9.3f")
estadd local p1=string(normal(-abs(_b[int_inc]/_se[int_inc]))*2, "%9.3f")
drop int_px int_inc interacted

local t1 " & \multicolumn{2}{c}{Non-Single} & \multicolumn{2}{c}{Non-Single} & \multicolumn{2}{c}{Single}    \\"
local t2 " & Married & LT Relationship & Female & Male & Female & Male   \\"
local t3 "&(1)&(2)&(3) & (4) & (5) & (6) \\ \midrule"

esttab ols5 ols6 ols1 ols2 ols3 ols4 using "results/AppendixTableA12.tex", se nonotes noconstant label replace booktabs gap compress keep(post_relpx post_relinc) order(post_relinc post_relpx )  b(%9.3f) se(%9.3f) star(* 0.1 ** 0.05 *** 0.01)  stats(r2_p N, fmt(%9.3f %9.0fc) labels("Pseudo \$ R^2 \$" "Observations")) nonumbers posthead("`t1'" "`t2'" "`t3'") mlabels(none) eqlabels(none) coeflabels(post_relinc "\$ \beta^{ER} \$" post_relpx "\$ \beta^{COL} \$")
* Note: q-values for multiple hypothesis testing calculated at end of dofile and manually added to table









*** Appendix Table A13: Location Preferences: Heterogeneity with Respect to Other Individual Characteristics
use "Main Experiment/mainexperiment_confidential.dta", clear

global controls "rel_res rel_qol lnpop reldens relblack reldemocrat relurban"

eststo clear

* Event A
probit baseline_finalrank post_relinc post_relpx lndiffwage $controls if low_eventa==0, robust
estimates store ols1

probit baseline_finalrank post_relinc post_relpx lndiffwage $controls if low_eventa==1, robust
estimates store ols2

local int low_eventa
gen int_px=`int'*post_relpx 
gen int_inc=`int'*post_relinc 
gen interacted=`int'

global intcontrols ""
foreach v in $controls {
	global intcontrols "${intcontrols} c.`v'#c.`int'"
	}

probit baseline_finalrank post_relpx post_relinc int_px int_inc interacted c.lndiffwage#c.interacted lndiffwage $controls $intcontrols , robust
estadd local p2=string(normal(-abs(_b[int_px]/_se[int_px]))*2, "%9.3f")
estadd local p1=string(normal(-abs(_b[int_inc]/_se[int_inc]))*2, "%9.3f")
drop int_px int_inc interacted

* Event B
probit baseline_finalrank post_relinc post_relpx lndiffwage $controls if low_eventb==0, robust
estimates store ols3

probit baseline_finalrank post_relinc post_relpx lndiffwage $controls if low_eventb==1, robust
estimates store ols4

local int low_eventb
gen int_px=`int'*post_relpx 
gen int_inc=`int'*post_relinc 
gen interacted=`int'

global intcontrols ""
foreach v in $controls {
	global intcontrols "${intcontrols} c.`v'#c.`int'"
	}

probit baseline_finalrank post_relpx post_relinc int_px int_inc interacted c.lndiffwage#c.interacted lndiffwage $controls $intcontrols , robust
estadd local p2=string(normal(-abs(_b[int_px]/_se[int_px]))*2, "%9.3f")
estadd local p1=string(normal(-abs(_b[int_inc]/_se[int_inc]))*2, "%9.3f")
drop int_px int_inc interacted


* Materialism
probit baseline_finalrank post_relinc post_relpx lndiffwage $controls if low_materialism==0, robust
estimates store ols5

probit baseline_finalrank post_relinc post_relpx lndiffwage $controls if low_materialism==1, robust
estimates store ols6

local int low_materialism
gen int_px=`int'*post_relpx 
gen int_inc=`int'*post_relinc 
gen interacted=`int'

global intcontrols ""
foreach v in $controls {
	global intcontrols "${intcontrols} c.`v'#c.`int'"
	}

probit baseline_finalrank post_relpx post_relinc int_px int_inc interacted c.lndiffwage#c.interacted lndiffwage $controls $intcontrols , robust
estadd local p2=string(normal(-abs(_b[int_px]/_se[int_px]))*2, "%9.3f")
estadd local p1=string(normal(-abs(_b[int_inc]/_se[int_inc]))*2, "%9.3f")
drop int_px int_inc interacted


* Competitiveness
probit baseline_finalrank post_relinc post_relpx lndiffwage $controls if low_competitive==0, robust
estimates store ols7

probit baseline_finalrank post_relinc post_relpx lndiffwage $controls if low_competitive==1, robust
estimates store ols8

local int low_competitive
gen int_px=`int'*post_relpx 
gen int_inc=`int'*post_relinc 
gen interacted=`int'

global intcontrols ""
foreach v in $controls {
	global intcontrols "${intcontrols} c.`v'#c.`int'"
	}

probit baseline_finalrank post_relpx post_relinc int_px int_inc interacted c.lndiffwage#c.interacted lndiffwage $controls $intcontrols , robust
estadd local p2=string(normal(-abs(_b[int_px]/_se[int_px]))*2, "%9.3f")
estadd local p1=string(normal(-abs(_b[int_inc]/_se[int_inc]))*2, "%9.3f")
drop int_px int_inc interacted


* Life Dimensions
cap: pca rank_happiness-rank_control
cap: predict scorerank
cap: replace scorerank=scorerank>0 if scorerank!=.

probit baseline_finalrank post_relinc post_relpx lndiffwage $controls if scorerank==0, robust
estimates store ols9

probit baseline_finalrank post_relinc post_relpx lndiffwage $controls if scorerank==1, robust
estimates store ols10

local int scorerank
gen int_px=`int'*post_relpx 
gen int_inc=`int'*post_relinc 
gen interacted=`int'

global intcontrols ""
foreach v in $controls {
	global intcontrols "${intcontrols} c.`v'#c.`int'"
	}

probit baseline_finalrank post_relpx post_relinc int_px int_inc interacted c.lndiffwage#c.interacted lndiffwage $controls $intcontrols , robust
estadd local p2=string(normal(-abs(_b[int_px]/_se[int_px]))*2, "%9.3f")
estadd local p1=string(normal(-abs(_b[int_inc]/_se[int_inc]))*2, "%9.3f")
drop int_px int_inc interacted


local t1a "  & \multicolumn{2}{c}{Hypothetical increase} & \multicolumn{2}{c}{Hypothetical increase} & \multicolumn{2}{c}{} & \multicolumn{2}{c}{} & \multicolumn{2}{c}{} \\ "
local t1b "  & \multicolumn{2}{c}{absolute consumption} & \multicolumn{2}{c}{relative consumption} & \multicolumn{2}{c}{By Materialism} & \multicolumn{2}{c}{By Competitiveness} & \multicolumn{2}{c}{By Life Dimension} \\ \cmidrule(lr){2-3}\cmidrule(lr){4-5}\cmidrule(lr){6-7}\cmidrule(lr){8-9}\cmidrule(lr){10-11}"
local t2 " & Better off & Same/Worse off & Better off & Same/Worse off & High  & Low  & High  & Low  & High  & Low  \\ "
local t3 " &(1)&(2)&(3)&(4)&(5)&(6)&(7)&(8)&(9)&(10) \\ \midrule"

esttab ols1 ols2 ols3 ols4 ols5 ols6 ols7 ols8 ols9 ols10 using "results/AppendixTableA13.tex", se nonotes noconstant label replace booktabs gap compress keep(post_relinc post_relpx) order(post_relinc post_relpx)  b(%9.3f) se(%9.3f) star(* 0.1 ** 0.05 *** 0.01)  stats(p1 p2 r2_p N, fmt(%9.3f %9.3f %9.3f %9.0fc) labels("Relative" "Absolute" "Pseudo \$R^2\$" "Observations")) nonumbers posthead("`t1a'" "`t1b'" "`t2'" "`t3'") mlabels(none) eqlabels(none) coeflabels(post_relinc "$\beta^{ER}$" post_relpx "$\beta^{COL}$")
* Note: q-values for multiple hypothesis testing calculated at end of dofile and manually added to table









*** Appendix Table A15: Location Preferences: Happiness Trade-Offs
use "Main Experiment/mainexperiment_confidential.dta", clear

global controls "rel_res rel_qol lnpop reldens relblack reldemocrat relurban"

eststo clear
cap: gen happier=happy>=4 if happy!=.
cap: gen lr_happier = lr_happy>=4 & lr_happy!=.

cap: gen relpx_diff = relpx_shown - relpx_cfact 
cap: gen relinc_diff = relinc_shown - relinc_cfact

* ALL
cap: drop RELINC0 RELPX0
gen RELINC0=post_relinc
gen RELPX0=post_relpx

probit happier RELPX0 RELINC0 lndiffwage $controls if finalrank!=. & lr_relpx!=., robust
eststo row1

ivprobit happier (RELPX0 RELINC0 = relinc_diff relpx_diff) relpx_cfact relinc_cfact lndiffwage $controls if finalrank!=. & lr_relpx!=., vce(robust)
eststo row2

ivprobit lr_happier (RELINC0 RELPX0 = relinc_diff relpx_diff) relpx_cfact relinc_cfact lndiffwage $controls gap_baseline gap_followup, vce(robust)
eststo row3

esttab, keep(RELINC0 RELPX0) order(RELINC0 RELPX0) se

mat list r(coefs)
mat define A=r(coefs)
eststo drop row*
local rnames : rownames A
local models : coleq A
local models : list uniq models

local i=0
foreach name in RELINC0 RELPX0 {
 local ++i
 local j 0
 cap: matrix drop b
 cap: matrix drop se
 cap: matrix drop p
 foreach model of local models {
 local ++j
 matrix tmp = A[`i', 3*`j'-2]
 if tmp[1,1]<. {
 matrix colnames tmp = `model'
 matrix b = nullmat(b), tmp
 matrix tmp[1,1] = A[`i', 3*`j'-1]
 matrix se = nullmat(se), tmp
 matrix tmp[1,1] = A[`i', 3*`j']
 matrix p = nullmat(p), tmp
 }
 }
 ereturn post b
 quietly estadd matrix se
 quietly estadd matrix p
 eststo `name'
 qui cou if finalrank!=. & lr_relpx!=.
 qui estadd scalar obs=r(N)

 }

esttab, se mtitle noobs star(* .1 ** .05 *** .01) stats(obs)

matrix drop A


* Non-Single
cap: drop RELINC1 RELPX1
gen RELINC1=post_relinc
gen RELPX1 = post_relpx

probit happier RELINC1 RELPX1 lndiffwage $controls if single==0 & finalrank!=. & lr_relpx!=., robust
eststo row1

ivprobit happier (RELINC1 RELPX1 = relinc_diff relpx_diff) relpx_cfact relinc_cfact lndiffwage $controls if single==0 & finalrank!=. & lr_relpx!=., vce(robust)
eststo row2

ivprobit lr_happier (RELINC1 RELPX1 = relinc_diff relpx_diff) relpx_cfact relinc_cfact lndiffwage $controls gap_baseline gap_followup if single==0, vce(robust)
eststo row3

esttab, keep(RELINC1 RELPX1) order(RELINC1 RELPX1) se

mat list r(coefs)
mat define A=r(coefs)
eststo drop row*
local rnames : rownames A
local models : coleq A
local models : list uniq models

local i=0
foreach name in RELINC1 RELPX1 {
 local ++i
 local j 0
 cap: matrix drop b
 cap: matrix drop se
 cap: matrix drop p
 foreach model of local models {
 local ++j
 matrix tmp = A[`i', 3*`j'-2]
 if tmp[1,1]<. {
 matrix colnames tmp = `model'
 matrix b = nullmat(b), tmp
 matrix tmp[1,1] = A[`i', 3*`j'-1]
 matrix se = nullmat(se), tmp
 matrix tmp[1,1] = A[`i', 3*`j']
 matrix p = nullmat(p), tmp
 }
 }
 ereturn post b
 quietly estadd matrix se
 quietly estadd matrix p
 eststo `name'
 qui cou if single==0 & finalrank!=. & lr_relpx!=.
 qui estadd scalar obs=r(N)
 
 }

esttab, se mtitle noobs star(* .1 ** .05 *** .01)

matrix drop A


* Single
cap: drop RELINC2 RELPX2
gen RELINC2=post_relinc
gen RELPX2= post_relpx

probit happier RELINC2 RELPX2 lndiffwage $controls if single==1 & finalrank!=. & lr_relpx!=., robust
eststo row1

ivprobit happier (RELINC2 RELPX2 = relinc_diff relpx_diff) relpx_cfact relinc_cfact lndiffwage $controls if single==1 & finalrank!=. & lr_relpx!=., vce(robust)
eststo row2

ivprobit lr_happier (RELINC2 RELPX2 = relinc_diff relpx_diff) relpx_cfact relinc_cfact lndiffwage $controls gap_baseline gap_followup if single==1, vce(robust)
eststo row3

esttab, keep(RELINC2 RELPX2) order(RELINC2 RELPX2) se

mat list r(coefs)
mat define A=r(coefs)
eststo drop row*
local rnames : rownames A
local models : coleq A
local models : list uniq models

local i=0
foreach name in RELINC2 RELPX2 {
 local ++i
 local j 0
 cap: matrix drop b
 cap: matrix drop se
 cap: matrix drop p
 foreach model of local models {
 local ++j
 matrix tmp = A[`i', 3*`j'-2]
 if tmp[1,1]<. {
 matrix colnames tmp = `model'
 matrix b = nullmat(b), tmp
 matrix tmp[1,1] = A[`i', 3*`j'-1]
 matrix se = nullmat(se), tmp
 matrix tmp[1,1] = A[`i', 3*`j']
 matrix p = nullmat(p), tmp
 }
 }
 ereturn post b
 quietly estadd matrix se
 quietly estadd matrix p
 eststo `name'
 qui cou if single==1 & finalrank!=. & lr_relpx!=.
 qui estadd scalar obs=r(N)
 }

esttab, se mtitle noobs star(* .1 ** .05 *** .01)

matrix drop A

local t0 " & \multicolumn{3}{c}{Panel A: \$ \beta^{ER} \$ } & \multicolumn{3}{c}{Panel B: \$ \beta^{COL} \$} \\ \cmidrule(lr){2-4} \cmidrule(lr){5-7} "
local t1 " & Non-Single & Single & All  & Non-Single & Single & All \\"
local t2 " &(1)&(2)&(3)&(4)&(5)&(6) \\ \midrule"

esttab  RELINC1 RELINC2 RELINC0  RELPX1 RELPX2 RELPX0 using "results/AppendixTableA15.tex", se nonotes noconstant label replace booktabs gap compress  b(%9.3f) se(%9.3f) star(* 0.1 ** 0.05 *** 0.01) nonumbers mlabels(none) eqlabels(none) coeflabels(row1 "Baseline" row2 "Experimental" row3 "Experimental \$+\$ Long Term") posthead("`t0'" "`t1'" "`t2'")










*** Appendix Table A16: Location Preferences: Alternative Regression Models

use "Main Experiment/mainexperiment_confidential.dta", clear

global controls "rel_res rel_qol lnpop reldens relblack reldemocrat relurban"

eststo clear

* ALL
cap: drop RELINC0 RELPX0
gen RELINC0=post_relinc
gen RELPX0=post_relpx

probit baseline_finalrank RELINC0 RELPX0 lndiffwage $controls, robust
eststo row1

probit baseline_finalrank RELINC0 RELPX0 lndiffwage $controls, robust
eststo row2: mfx

logit baseline_finalrank RELINC0 RELPX0 lndiffwage $controls, robust
eststo row3

logit baseline_finalrank RELINC0 RELPX0 lndiffwage $controls, robust
eststo row4: mfx

oprobit rank RELINC0 RELPX0 lndiffwage $controls, robust
eststo row5

reg baseline_finalrank RELINC0 RELPX0 lndiffwage $controls, robust
eststo row6

esttab, margin keep(RELINC0 RELPX0) order(RELINC0 RELPX0) se

mat list r(coefs)
mat define A=r(coefs)
eststo drop row*
local rnames : rownames A
local models : coleq A
local models : list uniq models

local i=0
foreach name in RELINC0 RELPX0 {
 local ++i
 local j 0
 cap: matrix drop b
 cap: matrix drop se
 cap: matrix drop p
 foreach model of local models {
 local ++j
 matrix tmp = A[`i', 4*`j'-3]
 if tmp[1,1]<. {
 matrix colnames tmp = `model'
 matrix b = nullmat(b), tmp
 matrix tmp[1,1] = A[`i', 4*`j'-2]
 matrix se = nullmat(se), tmp
 matrix tmp[1,1] = A[`i', 4*`j'-1]
 matrix p = nullmat(p), tmp
 }
 }
 ereturn post b
 quietly estadd matrix se
 quietly estadd matrix p
 eststo `name'
 qui cou if finalrank!=. & lr_relpx!=.
 qui estadd scalar obs=r(N)

 }

esttab, se mtitle noobs star(* .1 ** .05 *** .01) stats(obs)

matrix drop A


* Non-Single
cap: drop RELINC1 RELPX1
gen RELINC1=post_relinc
gen RELPX1 = post_relpx

probit baseline_finalrank RELINC1 RELPX1 lndiffwage $controls if single==0, robust
eststo row1

probit baseline_finalrank RELINC1 RELPX1 lndiffwage $controls if single==0, robust
eststo row2: mfx

logit baseline_finalrank RELINC1 RELPX1 lndiffwage $controls if single==0, robust
eststo row3

logit baseline_finalrank RELINC1 RELPX1 lndiffwage $controls if single==0, robust
eststo row4: mfx

oprobit rank RELINC1 RELPX1 lndiffwage $controls if single==0, robust
eststo row5

reg baseline_finalrank RELINC1 RELPX1 lndiffwage $control if single==0, robust
eststo row6

esttab, margin keep(RELINC1 RELPX1) order(RELINC1 RELPX1) se

mat list r(coefs)
mat define A0=r(coefs)
matselrc A0 A, c(9/32)
matrix drop A0
eststo drop row*
local rnames : rownames A
local models : coleq A
local models : list uniq models

local i=0
foreach name in RELINC1 RELPX1 {
 local ++i
 local j 0
 cap: matrix drop b
 cap: matrix drop se
 cap: matrix drop p
 foreach model of local models {
 local ++j
 matrix tmp = A[`i', 4*`j'-3]
 if tmp[1,1]<. {
 matrix colnames tmp = `model'
 matrix b = nullmat(b), tmp
 matrix tmp[1,1] = A[`i', 4*`j'-2]
 matrix se = nullmat(se), tmp
 matrix tmp[1,1] = A[`i', 4*`j'-1]
 matrix p = nullmat(p), tmp
 }
 }
 ereturn post b
 quietly estadd matrix se
 quietly estadd matrix p
 eststo `name'
 qui cou if single==0 & finalrank!=. & lr_relpx!=.
 qui estadd scalar obs=r(N)
 
 }

esttab, se mtitle noobs star(* .1 ** .05 *** .01)

matrix drop A


* Single
cap: drop RELINC2 RELPX2
gen RELINC2=post_relinc
gen RELPX2= post_relpx

probit baseline_finalrank RELINC2 RELPX2 lndiffwage $controls if single==1, robust
eststo row1

probit baseline_finalrank RELINC2 RELPX2 lndiffwage $controls if single==1, robust
eststo row2: mfx

logit baseline_finalrank RELINC2 RELPX2 lndiffwage $controls if single==1, robust
eststo row3

logit baseline_finalrank RELINC2 RELPX2 lndiffwage $controls if single==1, robust
eststo row4: mfx

oprobit rank RELINC2 RELPX2 lndiffwage $controls if single==1, robust
eststo row5

reg baseline_finalrank RELINC2 RELPX2 lndiffwage $controls if single==1, robust
eststo row6


esttab, margin keep(RELINC2 RELPX2) order(RELINC2 RELPX2) se

mat list r(coefs)
mat define A0=r(coefs)
matselrc A0 A, c(17/40)
matrix drop A0
eststo drop row*
local rnames : rownames A
local models : coleq A
local models : list uniq models

local i=0
foreach name in RELINC2 RELPX2 {
 local ++i
 local j 0
 cap: matrix drop b
 cap: matrix drop se
 cap: matrix drop p
 foreach model of local models {
 local ++j
 matrix tmp = A[`i', 4*`j'-3]
 if tmp[1,1]<. {
 matrix colnames tmp = `model'
 matrix b = nullmat(b), tmp
 matrix tmp[1,1] = A[`i', 4*`j'-2]
 matrix se = nullmat(se), tmp
 matrix tmp[1,1] = A[`i', 4*`j'-1]
 matrix p = nullmat(p), tmp
 }
 }
 ereturn post b
 quietly estadd matrix se
 quietly estadd matrix p
 eststo `name'
 qui cou if single==1 & finalrank!=. & lr_relpx!=.
 qui estadd scalar obs=r(N)
 }

esttab, se mtitle noobs star(* .1 ** .05 *** .01)

matrix drop A

local t0 " & \multicolumn{3}{c}{Panel A: \$ \beta^{ER} \$ } & \multicolumn{3}{c}{Panel B: \$ \beta^{COL} \$} \\ \cmidrule(lr){2-4} \cmidrule(lr){5-7} "
local t1 " & Non-Single & Single  & All & Non-Single & Single  & All \\"
local t2 " &(1)&(2)&(3)&(4)&(5)&(6) \\ \midrule"

esttab  RELINC1 RELINC2 RELINC0  RELPX1 RELPX2 RELPX0 using "results/AppendixTableA16.tex", se nonotes noconstant label replace booktabs gap compress  b(%9.3f) se(%9.3f) star(* 0.1 ** 0.05 *** 0.01) nonumbers mlabels(none) eqlabels(none) coeflabels(row1 "Probit" row2 "Probit MFX" row3 "Logit" row4 "Logit MFX" row5 "Ordered probit" row6 "Linear Probability Model") posthead("`t0'" "`t1'" "`t2'")










*** Appendix Table A17: Location Preferences: IV, First Stage, and Reduced Form Estimates
use "Main Experiment/mainexperiment_confidential.dta", clear

global controls "rel_res rel_qol lnpop reldens relblack reldemocrat relurban"

eststo clear

cap: gen relpx_diff = relpx_shown - relpx_cfact 
cap: gen relinc_diff = relinc_shown - relinc_cfact

ivprobit baseline_finalrank (post_relinc post_relpx  =relinc_diff relpx_diff ) relpx_cfact relinc_cfact lndiffwage $controls if finalrank!=. & lr_relpx!=., vce(robust)
estimates store ivop1
estadd local wte=string(e(p_exog), "%9.3f")
estadd local obs=string(e(N), "%9.0f")
ivreg2 baseline_finalrank (post_relpx post_relinc = relinc_diff relpx_diff ) relpx_cfact relinc_cfact lndiffwage $controls if finalrank!=. & lr_relpx!=., r first
estadd local fwi=e(cdf)

ivprobit baseline_finalrank (post_relinc post_relpx  =relinc_diff relpx_diff ) relpx_cfact relinc_cfact lndiffwage $controls if single==0 & finalrank!=. & lr_relpx!=., vce(robust)
estimates store ivop2
estadd local wte=string(e(p_exog), "%9.3f")
estadd local obs=string(e(N), "%9.0f")
ivreg2 baseline_finalrank (post_relpx post_relinc = relinc_diff relpx_diff ) relpx_cfact relinc_cfact lndiffwage $controls if single==0 & finalrank!=. & lr_relpx!=., r first
estadd local fwi=string(e(cdf), "%9.3f")

ivprobit baseline_finalrank (post_relinc post_relpx  =relinc_diff relpx_diff ) relpx_cfact relinc_cfact lndiffwage $controls if single==1 & finalrank!=. & lr_relpx!=., vce(robust)
estimates store ivop3
estadd local wte=string(e(p_exog), "%9.3f")
estadd local obs=string(e(N), "%9.0f")
ivreg2 baseline_finalrank (post_relpx post_relinc = relinc_diff relpx_diff ) relpx_cfact relinc_cfact lndiffwage $controls if single==1 & finalrank!=. & lr_relpx!=., r first
estadd local fwi=string(e(cdf), "%9.3f")

local t1 "& \multicolumn{3}{c}{IV-Probit} \\ \cmidrule(lr){2-4}"
local t2 " & Non-Single & Single & All \\"
local t3 "&(1)&(2)&(3) \\ \midrule"

esttab ivop2 ivop3 ivop1 using "results/AppendixTableA17.tex", se nonotes noconstant label replace booktabs gap compress keep(post_relpx post_relinc relinc_diff relpx_diff) order(post_relinc post_relpx relinc_diff relpx_diff )  b(%9.3f) se(%9.3f) star(* 0.1 ** 0.05 *** 0.01)  stats(obs wte fwi, fmt(%9.0fc %9.3f %9.3f) labels("Observations" "Wald test of exog. p-val." "Cragg-Donald F-stat.")) nonumbers posthead("`t1'" "`t2'" "`t3'") mlabels(none) noeqlines eqlabels("" "\midrule \multicolumn{@span}{l}{First stage} \\ \multicolumn{@span}{l}{Dep. Var.: \$ER\textsubscript{1,2}^i$}" "\multicolumn{@span}{l}{Dep. Var.: \$COL\textsubscript{1,2}^i$}"}) coeflabels(post_relpx "\$ \beta^{COL} \$" post_relinc "\$ \beta^{ER} \$"  relinc_diff "\$ \Delta ER_{1,2}^i \$" relpx_diff "\$ \Delta COL_{1,2}^i \$")

*** Reduced Form
eststo clear
cap: gen relpx_diff = relpx_shown - relpx_cfact 
cap: gen relinc_diff = relinc_shown - relinc_cfact

probit baseline_finalrank relinc_diff relpx_diff relpx_cfact relinc_cfact lndiffwage $controls if finalrank!=. & lr_relpx!=., vce(robust)
estimates store ols1

probit baseline_finalrank relinc_diff relpx_diff relpx_cfact relinc_cfact lndiffwage $controls if single==0 & finalrank!=. & lr_relpx!=., vce(robust)
estimates store ols2

probit baseline_finalrank relinc_diff relpx_diff relpx_cfact relinc_cfact lndiffwage $controls if single==1 & finalrank!=. & lr_relpx!=., vce(robust)
estimates store ols3

esttab ols2 ols3 ols1 using "results/AppendixTableA17.tex", se nonotes noconstant label append booktabs gap compress keep(relinc_diff relpx_diff) order(relinc_diff relpx_diff)  b(%9.3f) se(%9.3f) star(* 0.1 ** 0.05 *** 0.01)  stats(N, fmt(%9.0fc) labels("Observations")) nonumbers posthead("`t0'" "`t2'" "`t4'" "`t1'") mlabels(none) noeqlines coeflabels(relpx_diff "\$ \Delta COL\_{1,2}^i$" relinc_diff "\$Delta ER\_{1,2}^i$")










***
*** Estimate Q-Values for Multiple Testing
***

*** For Table 1
use "Main Experiment/mainexperiment_confidential.dta", clear

global controls "rel_res rel_qol lnpop reldens relblack reldemocrat relurban"

set seed 1

cap: gen highwage=perminc>229000 if perminc!=.

preserve
local int single
gen int_px=`int'*post_relpx 
gen int_inc=`int'*post_relinc 
gen interacted=`int'

global intcontrols ""
foreach v in $controls {
	global intcontrols "${intcontrols} c.`v'#c.`int'"
	}

parmby "probit baseline_finalrank post_relpx post_relinc int_px int_inc interacted c.lndiffwage#c.interacted lndiffwage $controls $intcontrols , robust", label norestore
drop if parm=="_cons"
gen model="NS-S"
tempfile aux
save "`aux'", replace
restore

preserve
local int male
gen int_px=`int'*post_relpx 
gen int_inc=`int'*post_relinc 
gen interacted=`int'

global intcontrols ""
foreach v in $controls {
	global intcontrols "${intcontrols} c.`v'#c.`int'"
	}

parmby "probit baseline_finalrank post_relpx post_relinc int_px int_inc interacted c.lndiffwage#c.interacted lndiffwage $controls $intcontrols , robust", label norestore
drop if parm=="_cons"
gen model="M-F"
append using "`aux'"
save "`aux'", replace
restore

preserve
local int highwage
gen int_px=`int'*post_relpx 
gen int_inc=`int'*post_relinc 
gen interacted=`int'

global intcontrols ""
foreach v in $controls {
	global intcontrols "${intcontrols} c.`v'#c.`int'"
	}

parmby "probit baseline_finalrank post_relpx post_relinc int_px int_inc interacted c.lndiffwage#c.interacted lndiffwage $controls $intcontrols , robust", label norestore
drop if parm=="_cons"
gen model="R-P"
append using "`aux'"
save "`aux'", replace
restore

* Baseline
preserve
parmby "probit baseline_finalrank post_relinc post_relpx lndiffwage $controls, robust", label norestore
drop if parm=="_cons"
gen model="baseline"
append using "`aux'"
save "`aux'", replace
restore


preserve
use "`aux'", clear

qqvalue p, method(simes) qvalue(myqval)
keep if parm=="int_inc" | parm=="int_px"
br
restore










*** For Appendix Table A12
use "Main Experiment/mainexperiment_confidential.dta", clear

global controls "rel_res rel_qol lnpop reldens relblack reldemocrat relurban"

set seed 1
preserve
local int low_eventa
gen int_px=`int'*post_relpx 
gen int_inc=`int'*post_relinc 
gen interacted=`int'

global intcontrols ""
foreach v in $controls {
	global intcontrols "${intcontrols} c.`v'#c.`int'"
	}

parmby "probit baseline_finalrank post_relpx post_relinc int_px int_inc interacted c.lndiffwage#c.interacted lndiffwage $controls $intcontrols , robust", label norestore
drop if parm=="_cons"
gen model="eventa"
tempfile aux
save "`aux'", replace
restore

preserve
local int low_eventb
gen int_px=`int'*post_relpx 
gen int_inc=`int'*post_relinc 
gen interacted=`int'

global intcontrols ""
foreach v in $controls {
	global intcontrols "${intcontrols} c.`v'#c.`int'"
	}

parmby "probit baseline_finalrank post_relpx post_relinc int_px int_inc interacted c.lndiffwage#c.interacted lndiffwage $controls $intcontrols , robust", label norestore
drop if parm=="_cons"
gen model="eventb"
append using "`aux'"
save "`aux'", replace
restore

preserve
local int low_materialism
gen int_px=`int'*post_relpx 
gen int_inc=`int'*post_relinc 
gen interacted=`int'

global intcontrols ""
foreach v in $controls {
	global intcontrols "${intcontrols} c.`v'#c.`int'"
	}

parmby "probit baseline_finalrank post_relpx post_relinc int_px int_inc interacted c.lndiffwage#c.interacted lndiffwage $controls $intcontrols , robust", label norestore
drop if parm=="_cons"
gen model="materialism"
append using "`aux'"
save "`aux'", replace
restore

preserve
local int low_competitive
gen int_px=`int'*post_relpx 
gen int_inc=`int'*post_relinc 
gen interacted=`int'

global intcontrols ""
foreach v in $controls {
	global intcontrols "${intcontrols} c.`v'#c.`int'"
	}

parmby "probit baseline_finalrank post_relpx post_relinc int_px int_inc interacted c.lndiffwage#c.interacted lndiffwage $controls $intcontrols , robust", label norestore
drop if parm=="_cons"
gen model="competitiveness"
append using "`aux'"
save "`aux'", replace
restore

preserve
cap: pca rank_happiness-rank_control
cap: predict scorerank
cap: replace scorerank=scorerank>0 if scorerank!=.

local int scorerank
gen int_px=`int'*post_relpx 
gen int_inc=`int'*post_relinc 
gen interacted=`int'

global intcontrols ""
foreach v in $controls {
	global intcontrols "${intcontrols} c.`v'#c.`int'"
	}

parmby "probit baseline_finalrank post_relpx post_relinc int_px int_inc interacted c.lndiffwage#c.interacted lndiffwage $controls $intcontrols , robust", label norestore
drop if parm=="_cons"
gen model="lifedim"
append using "`aux'"
save "`aux'", replace
restore


preserve
use "`aux'", clear

qqvalue p, method(simes) qvalue(myqval)
keep if parm=="int_inc" | parm=="int_px"
br
restore










*** For Appendix Table A13
use "Main Experiment/mainexperiment_confidential.dta", clear

global controls "rel_res rel_qol lnpop reldens relblack reldemocrat relurban"

set seed 1
preserve
local int male
gen int_px=`int'*post_relpx 
gen int_inc=`int'*post_relinc 
gen interacted=`int'

global intcontrols ""
foreach v in $controls {
	global intcontrols "${intcontrols} c.`v'#c.`int'"
	}

parmby "probit baseline_finalrank post_relpx post_relinc int_px int_inc interacted c.lndiffwage#c.interacted lndiffwage $controls $intcontrols if single==0, robust", label norestore
drop if parm=="_cons"
gen model="S-MF"
tempfile aux
save "`aux'", replace
restore

preserve
local int male
gen int_px=`int'*post_relpx 
gen int_inc=`int'*post_relinc 
gen interacted=`int'

global intcontrols ""
foreach v in $controls {
	global intcontrols "${intcontrols} c.`v'#c.`int'"
	}

parmby "probit baseline_finalrank post_relpx post_relinc int_px int_inc interacted c.lndiffwage#c.interacted lndiffwage $controls $intcontrols if single==1, robust", label norestore
drop if parm=="_cons"
gen model="NS-MF"
append using "`aux'"
save "`aux'", replace
restore

preserve
cap: gen married=marital==2
local int married
gen int_px=`int'*post_relpx 
gen int_inc=`int'*post_relinc 
gen interacted=`int'

global intcontrols ""
foreach v in $controls {
	global intcontrols "${intcontrols} c.`v'#c.`int'"
	}

parmby "probit baseline_finalrank post_relpx post_relinc int_px int_inc interacted c.lndiffwage#c.interacted lndiffwage $controls $intcontrols if single==0, robust", label norestore
drop if parm=="_cons"
gen model="M-LT"
append using "`aux'"
save "`aux'", replace
restore

preserve
use "`aux'", clear

qqvalue p, method(simes) qvalue(myqval)
keep if parm=="int_inc" | parm=="int_px"

restore

